package com.cykj.eurekaclient.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.cykj.eurekaclient.bean.*;
import com.cykj.eurekaclient.service.AdminService;
import com.cykj.eurekaclient.service.BusService;
import com.cykj.eurekaclient.utils.JsonXMLUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

@RestController
public class BusController {

    // 前端筛选的离起点1000米按近远排序的站点集合：距离，站点名
    private List<NearbySites> startNearbySiteList;
    // 前端筛选的离终点1000米按近远排序的站点集合：距离，站点名
    private List<NearbySites> endNearbySiteList;

    // 直达方案
    List<Transfer> directMap = new ArrayList<>();
    // 换乘方案
    List<Transfer> transferMap = new ArrayList<>();

    @Autowired
    private BusService busService;

    //获取公交列表
    @RequestMapping("/getBusList")
    public Map<String, Object> getBusList(@RequestBody Map<String, Object> map) throws Exception {
        PageConfig pageConfig = null;
        Bus bus = null;
        if (map.get("pageConfig") != null) {
            pageConfig = JsonXMLUtils.map2obj((Map<String, Object>) map.get("pageConfig"), PageConfig.class);
        }
        if (map.get("bus") != null) {
            bus = JsonXMLUtils.map2obj((Map<String, Object>) map.get("bus"), Bus.class);
        }
        System.out.println("获取公交列表");
        String cityId = bus.getCityname();

//        System.out.println("城市"+pageConfig.getCityId());
        System.out.println(pageConfig.getPage());
        Map<String, Object> remap = new HashMap<>();
        String licensePlate = bus.getLicensePlate() == null ? "" : "%" + bus.getLicensePlate() + "%";
        String maintainer = bus.getMaintainer() == null ? "" : "%" + bus.getMaintainer() + "%";
        long state = bus.getState();
        System.out.println(state + "状态");
        long routeId = bus.getRouteId();
        String fixedRoute = bus.getFixedRoute() == null ? "" : bus.getFixedRoute();
        System.out.println("车牌号" + licensePlate);
        System.out.println("维护人" + maintainer);
        remap.put("count", busService.selectAllBus(cityId, licensePlate, maintainer, state));
        remap.put("busList", busService.selectBusList(new RowBounds((pageConfig.getPage() - 1) * pageConfig.getLimit(), pageConfig.getLimit()), cityId, licensePlate, maintainer, state));
        System.out.println(busService.selectBusList(new RowBounds((pageConfig.getPage() - 1) * pageConfig.getLimit(), pageConfig.getLimit()), cityId, licensePlate, maintainer, state));
        return remap;

    }

    //添加公交
    @RequestMapping("/addBus")
    public boolean addBus(@RequestBody Bus bus) {
//        System.out.println("城市id"+bus.getCityId());
        int cityid = (int) (bus.getCityId());
        int fettleId = busService.selectFettle(bus.getMaintainer());
        System.out.println("城市id" + cityid);
        System.out.println("修理工" + fettleId);
//        String usedTime=bus.getRegistrationTime();
        String licensePlate = bus.getLicensePlate();
//        System.out.println(usedTime+"年限");
//        Data date=new Data();
        System.out.println("车牌号" + licensePlate);
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String registrationTime = formatter.format(date);
        System.out.println(registrationTime + "当前时间");
        if (busService.addBus(cityid, fettleId, registrationTime, licensePlate)) {
            return true;
        }
        return false;
    }

    //修改工交
    @RequestMapping("/updateBus")
    public boolean updateBus(@RequestBody Bus bus) {
        System.out.println("修改公交");
        System.out.println(bus.getBusState());
        int fettlerId = busService.selectFettle(bus.getMaintainer());
        int state = busService.SelectBusState(bus.getBusState());

        String licensePlate = bus.getLicensePlate();
        long id = bus.getId();
        System.out.println(fettlerId + "维修工" + state + "状态" + licensePlate + "车牌号");
        if (busService.updateBus(fettlerId, state, licensePlate, id)) {
            return true;
        }
        return false;
    }

    //删除公交
    @RequestMapping("/delBus")
    public boolean delBus(@RequestBody Bus bus) {
        System.out.println("删除公交" + bus.getId());
        if (busService.delBus(bus.getId())) {
            return true;
        }
        return false;
    }

    //停用公交
    @RequestMapping("/stopBus")
    public boolean stopBus(@RequestBody Bus bus) {
        System.out.println("停用公交");
        int busState = busService.SelectBusState("报废");
        if (busService.stopBus(bus.getId(), busState)) {
            return true;
        }
        return false;
    }

    //获取维修列表
    @RequestMapping("/getMaintainList")
    public Map<String, Object> getMaintainList(@RequestBody Map<String, Object> map) throws Exception {
        PageConfig pageConfig = null;
        Bus bus = null;
        if (map.get("pageConfig") != null) {
            pageConfig = JsonXMLUtils.map2obj((Map<String, Object>) map.get("pageConfig"), PageConfig.class);
        }
        if (map.get("bus") != null) {
            bus = JsonXMLUtils.map2obj((Map<String, Object>) map.get("bus"), Bus.class);
        }
        String licensePlate = bus.getLicensePlate() == null ? "" : "%" + bus.getLicensePlate() + "%";
        System.out.println("获取维修列表");
        String cityId = bus.getCityname();
        System.out.println(cityId + "城市id");
        System.out.println("车牌号" + licensePlate);
        Map<String, Object> remap = new HashMap<>();
        remap.put("count", busService.selectMaintainNum(cityId, licensePlate));
        remap.put("MaintainingList", busService.selectMaintaining(cityId));
        remap.put("AllMaintainList", busService.selectAllMaintain(new RowBounds((pageConfig.getPage() - 1) * pageConfig.getLimit(), pageConfig.getLimit()), cityId, licensePlate));
        return remap;
    }

    @RequestMapping("/getClasses")
    public Map<String, Object> getClasses() {
        Map<String, Object> map = new HashMap<>();
        map.put("ClassList", busService.selectClasses());
        return map;
    }

    @RequestMapping("/getBeginJourney")
    public Map<String, Object> getBeginJourney(@RequestBody RouteInfo routeInfo) {
        Map<String, Object> map = new HashMap<>();
        String routeName = routeInfo.getRouteName();
        System.out.println(routeName + "路线名");
        map.put("BeginJourneyList", busService.getBeginJourney(routeName));
        return map;
    }

    @RequestMapping("/carArrange")
    public boolean carArrange(@RequestBody BusTimeAssign busTimeAssign) {
        long routeId = busService.getBusRouteId(busTimeAssign.getRouteName());
        String beginTime = busTimeAssign.getBeginTime();
        long busId = busTimeAssign.getBusId();
        System.out.println("排班" + routeId + busId + beginTime);
        if (busService.addCarArrange(beginTime, routeId, busId)) {
            return true;
        }
        return false;
    }

    @RequestMapping("/carReArrange")
    public boolean carReArrange(@RequestBody BusTimeAssign busTimeAssign) {
        long id = busTimeAssign.getId();
        long busId = busTimeAssign.getBusId();
        System.out.println("换班" + id + busId);
        if (busService.carReArrange(id, busId)) {
            return true;
        }
        return false;
    }

    @RequestMapping("/getBusRoute")
    public String getBusRoute(@RequestBody RouteInfo routeInfo) {
        String routeName = routeInfo.getRouteName() == null ? "" : "%" + routeInfo.getRouteName() + "%";
        System.out.println(routeName + "路线名");
//        Map<String,Object> map=new HashMap<>();
        List<StationInfo> BusRouteList = busService.getBusRoute(routeName);
//        map.put("BusRouteList",busService.getBusRoute(routeName));

        return JSONArray.toJSONString(BusRouteList);
    }


    @RequestMapping("/getSearchInfo")
    public List<StationInfo> getSearchInfo(@RequestBody Map<String, String> data) {
        System.out.println("getSearchInfo");
//        String searchInfo = data.get("searchInfo");
        // 就可以直接用前端传过来的data去get其中的某个字段
        List<StationInfo> stationInfos = busService.selStationName(data.get("searchInfo"));
        // 返回到消费者的数据，转成了json
        return stationInfos;
    }

    // 用户搜索的线路名字模糊查询到相关线路
    @RequestMapping("/getRouteName")
    public List<String> getRouteName(@RequestBody Map<String, String> data) {
        System.out.println("getRouteName");
//        String searchInfo = data.get("searchInfo");

//        将所有的数字提取出来
        String str = data.get("routeName");
        str = str.trim();
        String routeName1 = "";
        if (str != null && !"".equals(str)) {
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
                    routeName1 += str.charAt(i);
                }
            }

        }
        System.out.println(routeName1);
        String routeName = "%" + routeName1 + "%";
        System.out.println("routeName" + routeName);

        // 就可以直接用前端传过来的data去get其中的某个字段
        List<String> selRouteName = busService.selRouteName(routeName);
        System.out.println("查到有几条线路：" + selRouteName.size());
        // 返回到消费者的数据，转成了json
        return selRouteName;
    }

    @RequestMapping("/getStationListMY")
    public List<StationInfo> getStationListMY(@RequestBody Map<String, String> data) {
        System.out.println("getStationListMY");
        // 就可以直接用前端传过来的data去get其中的某个字段
        List<StationInfo> stationInfos = busService.getStationListMY(data.get("district"));
        System.out.println("开始");
        System.out.println("stationInfos.size:" + stationInfos.size());
        for (StationInfo stationInfo : stationInfos) {
            System.out.println("stationInfo:" + stationInfo.getName());
        }
        System.out.println("结束");
        // 返回到消费者的数据，转成了json
        return stationInfos;
    }

    @RequestMapping("/deliveryStartSiteAll")
    public List<Transfer> deliveryStartSiteAll(@RequestBody Map<String, String> data) {
        directMap.clear();
        transferMap.clear();
//        System.out.println("进入deliveryStartSiteAll");
        startNearbySiteList = JSON.parseArray(data.get("siteAll"), NearbySites.class);
        for (NearbySites n : startNearbySiteList) {
//            System.out.println("start:" + n.getDistance() + "," + n.getStationInfo());
        }
        // 返回到消费者的数据，转成了json
//        System.out.println("分割。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。");

        // 拿到起点终点的相关站点后就开始做公交方案
        for (int startIndex = 0; startIndex < startNearbySiteList.size(); startIndex++) {

//            System.out.println("endNearbySiteList.:"+endNearbySiteList.size());
            for (int endIndex = 0; endIndex < endNearbySiteList.size(); endIndex++) {
                // 遍历两个站点判断是否属于同一条线路
                List<RouteInfo> routeInfos = busService.getRideScheme(startNearbySiteList.get(startIndex).getStationInfo(), endNearbySiteList.get(endIndex).getStationInfo());
//                System.out.println("routeInfos:" + routeInfos.size());
                if (routeInfos.size() != 0) {
                    System.out.println("两个站点属于同一条线路，可以直达");
                    for (RouteInfo routeInfo : routeInfos) {

                        // 将查到的公交路线放进map的val的第一条线路的站点集合里
                        Transfer transfer = new Transfer();
                        // 用第一条线路的名字查到所有的站点名字并按顺序排列
                        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//                        System.out.println("线路名字：" + routeInfo.getRouteName());
                        // 第一条路线的所有站点
                        List<StationInfo> stationInfos2 = busService.selStationName(routeInfo.getRouteName());

                        // 用户的起点
                        long startStationSequence = 0;
                        // 下车点
                        long downStationSequence = 0;
                        // 上车点
                        long upStationSequence = 0;
                        // 终点
                        long stopStationSequence = 0;

                        // 第一条线路
                        for (StationInfo stationInfo1 : stationInfos2) {
                            // 第一条线路上车站点的排序位置
                            // startNearbySiteList.get(startIndex).getStationInfo() stationInfo.getName()
                            if (stationInfo1.getName().equals(startNearbySiteList.get(startIndex).getStationInfo()) == true) {
                                startStationSequence = stationInfo1.getSequence();
                                // 取到第一条线路下车的排序位置
                            } else if (stationInfo1.getName().equals(endNearbySiteList.get(endIndex).getStationInfo()) == true) {
                                stopStationSequence = stationInfo1.getSequence();

                            }
                        }
//                        System.out.println("起点，终点顺序：" + startStationSequence + "," + stopStationSequence);
                        if ((startStationSequence != 0) && (stopStationSequence != 0) && (startStationSequence < stopStationSequence)) {
//                            System.out.println("第一条线的上车下车点排序不为0,且是正方向");
                            // 第二条线路中用上车和下车站点截取的行径站点
                            transfer.setFirstRouteInfos(busService.interceptStation(routeInfo.getRouteName(), startStationSequence, downStationSequence));
                        } else if ((startStationSequence != 0) && (stopStationSequence != 0) && (startStationSequence > stopStationSequence)) {
//                            System.out.println("第一条线的上车下车点排序不为0,且是反方向");
//                            System.out.println(stopStationSequence + "," + startStationSequence);
                            // 第二条线路中用上车和下车站点截取的行径站点
                            transfer.setFirstRouteInfos(busService.backInterceptStation(routeInfo.getRouteName(), stopStationSequence, startStationSequence));

                        }

                        // 将用户的起始站点放进换乘类
                        transfer.setStartBusStation(busService.useNameGetStationInfo(startNearbySiteList.get(startIndex).getStationInfo()));
                        // 将用户的下车站点放进换乘类
                        transfer.setDownBusStation(busService.useNameGetStationInfo(endNearbySiteList.get(endIndex).getStationInfo()));
                        // 终点
                        transfer.setStopBusStation(busService.useNameGetStationInfo(endNearbySiteList.get(endIndex).getStationInfo()));
                        // 将直达的线路名放进换乘类
                        transfer.setFirstRoute(routeInfo.getRouteName());
                        // 站点数
                        List<StationInfo> b = busService.backInterceptStation(routeInfo.getRouteName(), stopStationSequence, startStationSequence);
                        transfer.setStationCount(b.size());

                        transfer.setMoney(1);

                        // 判断是否有相同的线路，如果没有则存进数组
                        if (directMap.isEmpty() == false) {
                            System.out.println("pppppppppppppppppppppppppppppppppppppppppp:"+directMap.size());
                            boolean h = true;
                            for (int i = 0;i < directMap.size();i++){
                                System.out.println("lalallalalalalalaaaaaaaaaaaa");
                                System.out.println("directMap.get(i).getFirstRoute():"+directMap.get(i).getFirstRoute());
                                System.out.println("transfer.getFirstRoute():"+transfer.getFirstRoute());
                                if (directMap.get(i).getFirstRoute().equals(transfer.getFirstRoute()) == true) {
                                    System.out.println("单程插入了一次");
                                    h = false;
                                }
                            }
                            if (h == true){
                                // 将直达的线路名作为key，换乘类作为val，换乘类里有相关的数据
                                directMap.add(transfer);
                            }
//                            for (Transfer transfer1 : directMap) {
//                                if (transfer1.getFirstRoute().equals(transfer.getFirstRoute()) == false) {
//                                    // 将直达的线路名作为key，换乘类作为val，换乘类里有相关的数据
//                                    directMap.add(transfer);
//                                }
//                            }
                        } else {
                            directMap.add(transfer);
                        }

//                        System.out.println("directMap::::  routeInfo.getRouteName():" + routeInfo.getRouteName() + ",transfer:" + transfer);

                    }
//                    System.out.println("两个站点属于同一条线路，可以直达。起点为：" + startNearbySiteList.get(startIndex).getStationInfo() + ",终点为：" + endNearbySiteList.get(endIndex).getStationInfo());
                    // 如果判断有可以直达，那就将所有的线路集合返回给前端
                    // return routeInfos;
                } else {
                    System.out.println("两个站点不属于同一条线路，需要做换乘");
//                    System.out.println("lalala:" + startNearbySiteList.get(startIndex).getStationInfo());
                    // 用站点查路线
                    List<RouteInfo> routeInfos1 = busService.stationInRouteAll(startNearbySiteList.get(startIndex).getStationInfo());
//                    System.out.println("routeInfos1.size:" + routeInfos1.size());
                    for (RouteInfo routeInfo : routeInfos1) {
//                        System.out.println("第1" + "条线路的名字是：" + routeInfo.getRouteName());
                        // 根据路线查到对应的所有站点名字
                        List<StationInfo> stationInfos = busService.selStationName(routeInfo.getRouteName());
                        for (StationInfo stationInfo : stationInfos) {
                            // 用中转站点和终点比对看是否在同一条线路中
                            List<RouteInfo> routeInfos2 = busService.getRideScheme(stationInfo.getName(), endNearbySiteList.get(endIndex).getStationInfo());
                            if (routeInfos2.size() != 0) {
                                // 第二条公交线路
                                for (RouteInfo routeInfo1 : routeInfos2) {
                                    // 将查到的公交路线放进map的val的第一条线路的站点集合里
                                    Transfer transfer = new Transfer();
                                    // 用第一条线路的名字查到所有的站点名字并按顺序排列
                                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                                    // 第一条路线的所有站点
                                    List<StationInfo> stationInfos2 = busService.selStationName(routeInfo.getRouteName());
                                    // 第二条路线的所有站点
                                    List<StationInfo> stationInfos1 = busService.selStationName(routeInfo1.getRouteName());

                                    // 用户的起点
                                    long startStationSequence = 0;
                                    // 下车点
                                    long downStationSequence = 0;
                                    // 上车点
                                    long upStationSequence = 0;
                                    // 终点
                                    long stopStationSequence = 0;

                                    // 第一条线路
                                    for (StationInfo stationInfo1 : stationInfos2) {
                                        // 第一条线路上车站点的排序位置
//                                        startNearbySiteList.get(startIndex).getStationInfo() stationInfo.getName()
                                        if (stationInfo1.getName().equals(startNearbySiteList.get(startIndex).getStationInfo()) == true) {
                                            startStationSequence = stationInfo1.getSequence();
                                            // 取到第一条线路下车的排序位置
                                        } else if (stationInfo1.getName().equals(stationInfo.getName()) == true) {
                                            downStationSequence = stationInfo1.getSequence();

                                        }
                                    }
                                    if ((startStationSequence != 0) && (downStationSequence != 0) && (startStationSequence < downStationSequence)) {
//                                        System.out.println("第一条线的上车下车点排序不为0,且是正方向");
                                        // 第二条线路中用上车和下车站点截取的行径站点
                                        transfer.setFirstRouteInfos(busService.interceptStation(routeInfo.getRouteName(), startStationSequence, downStationSequence));
                                        List<StationInfo> aa = busService.interceptStation(routeInfo.getRouteName(), startStationSequence, downStationSequence);
                                        transfer.setStationCount(aa.size());

                                    } else if ((startStationSequence != 0) && (downStationSequence != 0) && (startStationSequence > downStationSequence)) {
//                                        System.out.println("第一条线的上车下车点排序不为0,且是反方向");
//                                        System.out.println(downStationSequence + "," + startStationSequence);
                                        // 第二条线路中用上车和下车站点截取的行径站点
                                        transfer.setFirstRouteInfos(busService.backInterceptStation(routeInfo.getRouteName(), downStationSequence, startStationSequence));
                                        List<StationInfo> aa = busService.backInterceptStation(routeInfo.getRouteName(), downStationSequence, startStationSequence);
                                        transfer.setStationCount(aa.size());

                                    }

                                    // 第二条线路
                                    for (StationInfo stationInfo1 : stationInfos1) {
                                        // 第二条线路上车站点的排序位置
                                        if (stationInfo1.getName().equals(stationInfo.getName()) == true) {
                                            upStationSequence = stationInfo1.getSequence();
                                            // 取到终点的排序位置
                                        } else if (stationInfo1.getName().equals(endNearbySiteList.get(endIndex).getStationInfo()) == true) {
                                            stopStationSequence = stationInfo1.getSequence();

                                        }
                                    }
                                    if ((upStationSequence != 0) && (stopStationSequence != 0) && (upStationSequence < stopStationSequence)) {
//                                        System.out.println("第二条线的上车下车点排序不为0,且是正方向");
                                        // 第二条线路中用上车和下车站点截取的行径站点
                                        transfer.setSecondRouteInfos(busService.interceptStation(routeInfo1.getRouteName(), upStationSequence, stopStationSequence));
                                        List<StationInfo> aa = busService.interceptStation(routeInfo1.getRouteName(), upStationSequence, stopStationSequence);
                                        if (transfer.getStationCount() != 0) {
                                            int b = transfer.getStationCount();
                                            int c = aa.size();
                                            int d = b + c;
                                            transfer.setStationCount(d);
                                        }

                                    } else if ((upStationSequence != 0) && (stopStationSequence != 0) && (upStationSequence > stopStationSequence)) {
//                                        System.out.println("第二条线的上车下车点排序不为0,且是反方向");
//                                        System.out.println(stopStationSequence + "," + upStationSequence);
                                        // 第二条线路中用上车和下车站点截取的行径站点
                                        transfer.setSecondRouteInfos(busService.backInterceptStation(routeInfo1.getRouteName(), stopStationSequence, upStationSequence));
                                        List<StationInfo> aa = busService.backInterceptStation(routeInfo1.getRouteName(), stopStationSequence, upStationSequence);
                                        if (transfer.getStationCount() != 0) {
                                            int b = transfer.getStationCount();
                                            int c = aa.size();
                                            int d = b + c;
                                            transfer.setStationCount(d);
                                        }

                                    }

                                    transfer.setMoney(2);
                                    // 将用户的起始站点放进换乘类
                                    transfer.setStartBusStation(busService.useNameGetStationInfo(startNearbySiteList.get(startIndex).getStationInfo()));
                                    // 将用户的下车站点放进换乘类
                                    transfer.setDownBusStation(busService.useNameGetStationInfo(stationInfo.getName()));
                                    // 上车站点
                                    transfer.setUpBusStation(busService.useNameGetStationInfo(stationInfo.getName()));
                                    // 终点
                                    transfer.setStopBusStation(busService.useNameGetStationInfo(endNearbySiteList.get(endIndex).getStationInfo()));
                                    // 第一条线路名
                                    transfer.setFirstRoute(routeInfo.getRouteName());

                                    // 第二条线路名
                                    transfer.setSecondRoute(routeInfo1.getRouteName());

                                    // 判断是否有相同的线路，如果没有则存进数组
                                    if (transferMap.isEmpty() == false) {
                                        boolean t = true;
                                        for (int i = 0;i < transferMap.size();i++){
                                            if (transferMap.get(i).getFirstRoute().equals(transfer.getFirstRoute()) == true && (transferMap.get(i).getSecondRoute().equals(transfer.getSecondRoute()) == true)) {
                                                t = false;
                                            }
                                        }
                                        if (t== true){
                                            System.out.println("换乘进入一次");
                                            transferMap.add(transfer);
                                        }

//                                        for (Transfer transfer1 : transferMap) {
//                                            if ((transfer1.getFirstRoute().equals(transfer.getFirstRoute()) == false) || (transfer1.getSecondRoute().equals(transfer.getSecondRoute()) == false)) {
//                                                // 将直达的线路名作为key，换乘类作为val，换乘类里有相关的数据
//                                                transferMap.add(transfer);
//                                            }
//                                        }
                                    } else {
                                        // 将直达的线路名作为key，换乘类作为val，换乘类里有相关的数据
                                        transferMap.add(transfer);
                                    }
//                                    System.out.println("transferMap::::  routeInfo1.getRouteName():" + routeInfo1.getRouteName() + ",transfer:" + transfer);

                                }
                            }
                        }
                    }
                }
            }
        }

        System.out.println("directMap.isEmpty():" + directMap.isEmpty());
        System.out.println("transferMap.isEmpty():" + transferMap.isEmpty());

        // isEmpty()方法判断Map是否有内容（即new分配空间后是否put键值对），若没有内容则true，否则false如果不为空说明有公交方案则返回数据给前端
        // directMap transferMap
        if (directMap.isEmpty() == false && transferMap.isEmpty() == true) {
            System.out.println("单程方案不为空");
            for (Transfer transfer : directMap) {
                System.out.println("用户的起始站点：" + transfer.getStartBusStation());
                System.out.println("下车站点:" + transfer.getDownBusStation());
                System.out.println("上车站点:" + transfer.getUpBusStation());
                System.out.println("第一条线路名:" + transfer.getFirstRoute());
                System.out.println("第一条线路行径的站点:" + transfer.getFirstRouteInfos());
                System.out.println("第二条线路名:" + transfer.getSecondRoute());
                System.out.println("第二条线路行径的站点:" + transfer.getSecondRouteInfos());
            }
            return directMap;

        } else if (directMap.isEmpty() == true && transferMap.isEmpty() == false) {
            System.out.println("换乘方案不为空");
            for (Transfer transfer : transferMap) {
                System.out.println("用户的起始站点：" + transfer.getStartBusStation());
                System.out.println("下车站点:" + transfer.getDownBusStation());
                System.out.println("上车站点:" + transfer.getUpBusStation());
                System.out.println("第一条线路名:" + transfer.getFirstRoute());
                System.out.println("第一条线路行径的站点:" + transfer.getFirstRouteInfos());
                System.out.println("第二条线路名:" + transfer.getSecondRoute());
                System.out.println("第二条线路行径的站点:" + transfer.getSecondRouteInfos());
            }
            return transferMap;
        } else if (directMap.isEmpty() == false && transferMap.isEmpty() == false) {
            System.out.println("两个方案都不为空");
            for (Transfer transfer : transferMap) {
                System.out.println("用户的起始站点：" + transfer.getStartBusStation());
                System.out.println("下车站点:" + transfer.getDownBusStation());
                System.out.println("上车站点:" + transfer.getUpBusStation());
                System.out.println("第一条线路名:" + transfer.getFirstRoute());
                System.out.println("第一条线路行径的站点:" + transfer.getFirstRouteInfos());
                System.out.println("第二条线路名:" + transfer.getSecondRoute());
                System.out.println("第二条线路行径的站点:" + transfer.getSecondRouteInfos());
                directMap.add(transfer);
            }
            return transferMap;
        }

        return null;
    }

    @RequestMapping("/deliveryEndSiteAll")
    public void deliveryEndSiteAll(@RequestBody Map<String, String> data) {
        System.out.println("deliveryEndSiteAll");
        endNearbySiteList = JSON.parseArray(data.get("siteAll"), NearbySites.class);
        for (NearbySites n : endNearbySiteList) {
            System.out.println("end:" + n.getDistance() + "," + n.getStationInfo());
        }
        // 返回到消费者的数据，转成了json


    }

}
